import request from '@/utils/goods';
import type {
  CategoryResponeDate,
  AttrList,
  Attr1,
  Attr,
} from '@/api/product/attr/types/index';

// 枚举定义接口
enum API_URL {
  //一级分类请求地址
  C1_URL = '/admin/product/getCategory1',
  // 二级分类请求地址
  C2_URL = '/admin/product/getCategory2/',
  // 三级分类请求地址
  C3_URL = '/admin/product/getCategory3/',
  // 获取某一个三级分类下的数据
  ATTR_URL = '/admin/product/attrInfoList/',
  // 更新和添加商品属性
  ADDORUPDATEATTR = '/admin/product/saveAttrInfo',
  // 删除已有的属性
  DELETEATTR = '/admin/product/deleteAttr/',
}

// 获取一级商品的接口
export const reqC1 = () => {
  return request.get<any, CategoryResponeDate>(
    API_URL.C1_URL
  );
};
// 获取二级商品的接口
export const reqC2 = (category1Id: number) => {
  return request.get<any, CategoryResponeDate>(
    API_URL.C2_URL + category1Id
  );
};
// 获取三级商品的接口
export const reqC3 = (category2Id: number) => {
  return request.get<any, CategoryResponeDate>(
    API_URL.C3_URL + category2Id
  );
};
// 获取某一个三级分类下已有的属性与属性值的接口
export const reqAttr = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return request.get<any, AttrList>(
    API_URL.ATTR_URL +
      `${category1Id}/${category2Id}/${category3Id}`
  );
};
// 添加和修改商品属性的接口
export const reqAddOrUpdateAttr = (data: Attr1) => {
  return request.post<any, AttrList>(
    API_URL.ADDORUPDATEATTR,
    data
  );
};
// 删除已有属性的接口
export const reqDeleteAttr = (attrId: number) => {
  return request.delete(API_URL.DELETEATTR + attrId);
};
